#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 205;
const int M = 1e5 + 5;

int n, m;
ll c[N], d[N];
int head[N], ind[N];
int ver[M], W[M], Next[M], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
void toposort() {
  vector<int> now, nxt;
  rep(i, 1, n) if (!ind[i]) now.push_back(i);
  while (now.size() && head[now.front()]) {
    for (int u : now) {
      for (int i = head[u]; i; i = Next[i]) {
        int v = ver[i];
        int w = W[i];
        c[v] += w * c[u];
        if (--ind[v] == 0) nxt.push_back(v), c[v] = max(c[v] - d[v], 0ll);
      }
    }
    now.clear();
    swap(now, nxt);
  }
  int cnt = 0;
  sort(now.begin(), now.end());
  for (int x : now)
    if (c[x] > 0) cnt++, cout << x << ' ' << c[x] << endl;
  if (!cnt) cout << "NULL";
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> c[i] >> d[i];
  rep(i, 1, m) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w);
    ind[v]++;
  }
  toposort();
  return 0;
}